#' Replace Variables
#' @param regdata original data frame
#' @param fromvar character, a replaced variable in \code{regdata}
#' @param todata a data frame whose variables replace variables in \code{regdata}
#' @param tovar character, a variable in \code{todata}
#' @importFrom magrittr '%>%'
ReplaceVar <- function(regdata, fromvar = 'USA_unctn', todata = unctnMain, tovar = 'tomo'){
  regdata <- merge(regdata, todata[,c('date',tovar)], by = 'date', all.x = T)
  regdata <- dplyr::select(regdata, -fromvar)
  eval(parse(text = paste('regdata <- dplyr::rename(regdata,', fromvar,'=', tovar,')',sep = '')))
  return(regdata)
}



